package com.phcx.corporate.utils;

import com.phcx.corporate.model.AdminInfo;
import com.phcx.corporate.vo.AdminInfoDataVoOne;
import org.springframework.util.StringUtils;

/*
 * @Author: zmh
 * @Date: 2023/05/24/10:47
 * @Description:
 */
public class ModelUtil {

    public static AdminInfo adminVo2Info(AdminInfoDataVoOne vo){
        String [] licence42Code = vo.getLicence42Code();
//        String[][] licence42Code = vo.getLicence42Code();
        String value = licence42Code[2];
//        for (int i = 0; i < licence42Code.length; i++) {
//           value += licence42Code[i];
//        }
        value = value.trim().replaceAll("^,|,$", "");

        AdminInfo Info = new AdminInfo();
        if(StringUtils.isEmpty(vo.getAdminId())){
            Info.setAdminId(TableUtil.getID());
        }else{
            Info.setAdminId(vo.getAdminId());
        }
        Info.setAdminName(vo.getAdminName());
        Info.setUsername(vo.getUsername());
        Info.setPassword(vo.getPassword());
        Info.setLicence42Code(value);
        Info.setAccountType(vo.getAccountType());
        return Info;
    }

    public static AdminInfoDataVoOne adminInDataVo(AdminInfo info){
        String licence42Code = info.getLicence42Code();
        String [] arr = {"",null,licence42Code};

        AdminInfoDataVoOne adminInDataVo = new AdminInfoDataVoOne();
        adminInDataVo.setAdminId(info.getAdminId());
        adminInDataVo.setAdminName(info.getAdminName());
        adminInDataVo.setUsername(info.getUsername());
        adminInDataVo.setPassword(info.getPassword());
        adminInDataVo.setLicence42Code(arr);
        adminInDataVo.setAccountType(info.getAccountType());
        return adminInDataVo;
    }

    // 级联选择器多选时用的转换工具
//    public static AdminInfo adminVo2Info(AdminInDataVo vo){
//        String[][] licence42Code = vo.getLicence42Code();
//        String value = "";
//        for (int i = 0; i < licence42Code.length; i++) {
//            String[] row = licence42Code[i];
//            value += row[2]+",";
//        }
//        value = value.trim().replaceAll("^,|,$", "");
//
//        AdminInfo Info = new AdminInfo();
//        if(StringUtils.isEmpty(vo.getAdminId())){
//            Info.setAdminId(TableUtil.getID());
//        }else{
//            Info.setAdminId(vo.getAdminId());
//        }
//        Info.setAdminName(vo.getAdminName());
//        Info.setUsername(vo.getUsername());
//        Info.setPassword(vo.getPassword());
//        Info.setLicence42Code(value);
//        Info.setAccountType(vo.getAccountType());
//        return Info;
//    }

//    public static AdminInfoDataVo adminInDataVo(AdminInfo info){
//        String licence42Code = info.getLicence42Code();
//        String [] arr = licence42Code.split(",");
//        int len = arr.length;
//        String[][] strings = new String[len][3];
//        for (int i = 0; i < arr.length; i++) {
//            for (int j = 0; j < 3; j++) {
//                if(j==2){
//                    strings[i][j] = arr[i];
//                }else {
//                    strings[i][j] = "";
//                }
//            }
//        }
//        AdminInfoDataVo adminInDataVo = new AdminInfoDataVo();
//        adminInDataVo.setAdminId(info.getAdminId());
//        adminInDataVo.setAdminName(info.getAdminName());
//        adminInDataVo.setUsername(info.getUsername());
//        adminInDataVo.setPassword(info.getPassword());
//        adminInDataVo.setLicence42Code(strings);
//        adminInDataVo.setAccountType(info.getAccountType());
//        return adminInDataVo;
//    }
}
